﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Group3.Data.Interface;


namespace Group3.MediaTool.Data.Interface
{
    public abstract class IDataGenerator
    {
        List<DataLine> _definitionLines = new List<DataLine>();
        public List<DataLine> DefinitionLines
        {
            get { return _definitionLines;}
            set { _definitionLines = value;}
        }

        String _backEndDefinition;
        public String BackEndDefinition
        {
            get { return _backEndDefinition; }
            set { _backEndDefinition = value; }
        }




        public abstract void createBackEndScript();

        void writeDefinition(String pClassname)
        {
            String _dataDefinition = "";

            if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataDefinition")))
                Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataDefinition"));
            if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataDefinition\\D_" + pClassname + ".dd")))
                File.Delete(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataDefinition\\D_" + pClassname + ".dd"));

            StreamWriter sw = new StreamWriter(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataDefinition\\D_" + pClassname + ".dd"));

            foreach (DataLine s in DefinitionLines)
            {
                _dataDefinition = _dataDefinition + s.ToString() ;

            }
            _dataDefinition = _dataDefinition + Environment.NewLine;
            sw.Write(_dataDefinition);
            sw.Close();
        }

       public void markDefinitionScriptDone()
        {

            String _className = "";

            foreach (DataLine s in DefinitionLines)
            {
                if (String.IsNullOrEmpty(_className))
                {
                    _className = s.Classname;
                }
                s.Activity = "e";
            }
            writeDefinition(_className);
        }
    }
}
